package com.lyf.scm.admin.domain.remote.allocationservice.facade;


import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.SalesPlanOtherDTO;
import com.lyf.scm.admin.api.dto.SalesPlanOtherDifferinInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanOtherDifferinRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * 其他渠道计划_目标与销售计划差异正面
 *
 * @author: huangtao
 * @data: 2020/7/31
 */
@Service
@Slf4j
public class SalesPlanOtherDifferinFacade {

    @Resource
    private SalesPlanOtherDifferinRemote salesPlanOtherDifferinRemote;

    /**
     * 按条件查询其他渠道计划_目标与销售计划差异(周)
     * @param salesPlanOtherDTO
     * @return
     */
    public PageInfo<SalesPlanOtherDifferinInfoDTO> listWeekBySelective(SalesPlanOtherDTO salesPlanOtherDTO) {
        log.info("按条件查询其他渠道计划_目标与销售计划差异(周):salesPlanOtherDTO:{}", salesPlanOtherDTO);
        Response<PageInfo<SalesPlanOtherDifferinInfoDTO>> response = salesPlanOtherDifferinRemote.listWeekBySelective(salesPlanOtherDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 查询其他渠道计划_目标与销售计划差异(范围)
     * @param salesPlanOtherDTO
     * @return
     */
    public List<SalesPlanOtherDifferinInfoDTO> listAllByCycles(SalesPlanOtherDTO salesPlanOtherDTO) {
        log.info("查询其他渠道计划_目标与销售计划差异(范围):salesPlanOtherDTO:{}", salesPlanOtherDTO);
        Response<List<SalesPlanOtherDifferinInfoDTO>> response = salesPlanOtherDifferinRemote.listAllByCycles(salesPlanOtherDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 导出
     *
     * @param salesPlanOtherDTO
     * @param type
     * @return
     */
    public feign.Response export(SalesPlanOtherDTO salesPlanOtherDTO,Integer type) {
        log.info("其他渠道计划_目标与销售计划差异导出:salesPlanOtherAccuracy:{}", salesPlanOtherDTO);
        return salesPlanOtherDifferinRemote.export(salesPlanOtherDTO,type);
    }

    public void delete(String opSign) {
        log.info("删除其他渠道计划_目标与销售计划差异:{}", JSON.toJSONString(opSign));
        salesPlanOtherDifferinRemote.delete(opSign);
    }
}
